package com.ifp.opengate.boot.gateway.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import com.ifp.core.log.Trace;

/**
 * @Classname ConnectorAspect
 * @Description TODO
 * @Date 2019/7/10 11:32
 * @Created by zzh
 *          <p>
 *          zhuzh@belink.com
 *          </p>
 * @Version 1.0
 */
@Component
@Aspect
public class ConnectorAspect {

    @Pointcut(value = "execution(* sendAndReceive(..))&&target(com.ifp.core.connector.AbstractConnector)")
    public void logPointcut() {}

    @Before("logPointcut()")
    public void requestBefore(JoinPoint joinPoint) {
        if (null != joinPoint) {
            Object[] args = joinPoint.getArgs();
            Trace.log(joinPoint.getTarget().toString(), Trace.LEVEL_INFO, args[0] + ":" + args[1] + " is requested");
        }
    }

    @After("logPointcut()")
    public void requestAfter(JoinPoint joinPoint) {
        if (null != joinPoint) {
            Object[] args = joinPoint.getArgs();
            Trace.log(joinPoint.getTarget().toString(), Trace.LEVEL_INFO,
                args[0] + ":" + args[1] + "already is requested end");
        }
    }
}
